package org.lzfto.flink.demo.business.flinkTest.base.db;

public class CustomJdbcTable extends BasicJdbcTable {

	// cust-jdbc的额外属性
	private String driverClass;
	private String idColCode;

	public String getDriverClass() {
		return driverClass;
	}

	public void setDriverClass(String driverClass) {
		this.driverClass = driverClass;
	}

	public String getIdColCode() {
		return idColCode;
	}

	public void setIdColCode(String idColCode) {
		this.idColCode = idColCode;
	}

	@Override
	public String build() throws Exception {
		if (this.getConnector() == null) {
			throw new Exception("请先设置连接器connector属性");
		}
		// 标准SQL;
		if (this.getConnector().equals(STD_JDBC_CONNECTOR)) {
			String result = """
					with(
					  'connector'='%s',
					  'url' = '%s',
					  'table-name' = '%s',
					  'username' = '%s',
					  'password' = '%s'
					)
					""".formatted(this.getConnector(), this.getUrl(), this.getTableName(), this.getUserName(),
					this.getPassword());
			return result;
		} else if (this.getConnector().equals(CUST_JDBC_CONNECTOR)) {
			String result = """
					with(
					  'connector'='%s',
					  'url' = '%s',
					  'table-name' = '%s',
					  'username' = '%s',
					  'password' = '%s',
					  'idColCode'='%s',
					  'driver-class'='%s'
					)
					""".formatted(this.getConnector(), this.getUrl(), this.getTableName(), this.getUserName(),
					this.getPassword(), idColCode, driverClass == null ? "" : driverClass);
			return result;
		} else {
			throw new Exception("不支持的连接器:" + this.getConnector());
		}

	}

}
